package com.yiyi.repository;

import com.yiyi.entity.StudentLongyiyi;
import com.yiyi.form.SearchStudentForm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author yiyi
 * @date 2021/6/23
 */
public interface StudentRepository extends JpaRepository<StudentLongyiyi, Integer> {

    /**
     * 搜索及分页展示
     *
     * @param pageable
     * @param from
     * @return
     * */
    @Query(value = "select * " +
                "from student_longyiyi " +
                "where 1=1 " +
                "and (student_id=:#{#from.studentId} or :#{#from.studentId} is null) " +
                "and (student_name like:#{#from.studentName} or :#{#from.studentName} is null) " +
                "and (student_gender=:#{#from.studentGender} or :#{#from.studentGender} is null) " +
                "and (student_class like:#{#from.studentClass} or :#{#from.studentClass} is null)",
            nativeQuery = true)
    Page<StudentLongyiyi> findByPage(Pageable pageable, @Param("from") SearchStudentForm from);
}
